import BaseHTTPServer
import SimpleHTTPServer
import cgi

index = 'test.html'
PORT = 9000


class TestHandler ( SimpleHTTPServer.SimpleHTTPRequestHandler ):

	def do_GET ( self ):
		print "GET " + self.path
		f = self.path [ 1 : ]
		if not f: f = index
		self.wfile.write ( open ( f ).read () )

	def do_POST ( self ):
		print "POST " + self.path
		ctype, pdict = cgi.parse_header(self.headers.getheader('content-type'))
		parts = cgi.parse_multipart ( self.rfile, pdict )
		#open ( 'output.raw', 'w' ).write ( parts.keys )
		print "[keys] : %s" % parts.keys ()
		self.wfile.write ( "OK" )


server_address = ( "", PORT )
server = BaseHTTPServer.HTTPServer ( server_address, TestHandler )
server.serve_forever ()
